package clusterServer

import (
	"context"
	v1 "devops-super/api/clusters/v1"
	"devops-super/internal/model/entity"
	"devops-super/internal/service"

	"github.com/gogf/gf/v2/os/gtime"
)

func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.ClusterServerPageLstReq) (res *v1.ClusterServerPageLstRes, err error) {
	res = &v1.ClusterServerPageLstRes{}
	res.PageLstRes, err = service.ClusterServer().GetPageLst(ctx, req.PageLstReq)
	return
}

func (*ControllerV1) Add(ctx context.Context, req *v1.ClusterServerAddReq) (res *v1.ClusterServerAddRes, err error) {
	server := &entity.AppClusterServer{
		Name:              req.Name,
		ServerKey:         req.ServerKey,
		Remark:            req.Remark,
		PublicIp:          req.PublicIp,
		InnerIp:           req.InnerIp,
		TotalDataDiskSize: req.TotalDataDiskSize,
		DataDiskPath:      req.DataDiskPath,
		WebPort:           req.WebPort,
		CreatedAt:         gtime.Now(),
	}
	err = service.ClusterServer().Add(ctx, server)
	return
}

func (*ControllerV1) Upt(ctx context.Context, req *v1.ClusterServerUptReq) (res *v1.ClusterServerUptRes, err error) {
	server := &entity.AppClusterServer{
		Id:                int64(req.Id),
		Name:              req.Name,
		ServerKey:         req.ServerKey,
		Remark:            req.Remark,
		PublicIp:          req.PublicIp,
		InnerIp:           req.InnerIp,
		TotalDataDiskSize: req.TotalDataDiskSize,
		DataDiskPath:      req.DataDiskPath,
		WebPort:           req.WebPort,
		UpdatedAt:         gtime.Now(),
	}
	err = service.ClusterServer().Upt(ctx, server)
	return
}

func (*ControllerV1) Del(ctx context.Context, req *v1.ClusterServerDelReq) (res *v1.ClusterServerDelRes, err error) {
	err = service.ClusterServer().Del(ctx, req.Id)
	return
}

func (*ControllerV1) GetOne(ctx context.Context, req *v1.ClusterServerGetOneReq) (res *v1.ClusterServerGetOneRes, err error) {
	res1, err := service.ClusterServer().GetOne(ctx, req.Id)
	if err != nil {
		return
	}
	res = new(v1.ClusterServerGetOneRes)
	res.Info = res1
	return
}

func (*ControllerV1) GetOptions(ctx context.Context, req *v1.ClusterServerGetOptionsReq) (res *v1.ClusterServerGetOptionsRes, err error) {
	res, err = service.ClusterServer().GetOptions(ctx, req)
	return
}

func (*ControllerV1) GetClusterKeys(ctx context.Context, req *v1.ClusterServerGetClusterKeysReq) (res *v1.ClusterServerGetClusterKeysRes, err error) {
	res, err = service.ClusterServer().GetClusterKeys(ctx, req)
	return
}
